<template>
  <el-container class="bg_box">
    <el-header>
      <div>
        <img src="../assets/heima.png" alt="">
        <span>电商后台系统</span>
      </div>
      <el-button type="primary" @click="out">退出</el-button>
    </el-header>
    <el-container>

      <el-aside :width="toggle ? 64 + 'px': 200 + 'px'">
        <div class="toggle_menu" @click="toggle_menu">|||</div>
        <el-menu
          class="el-menu-vertical-demo"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF" unique-opened :collapse="toggle" :collapse-transition="false" :router="true" :default-active="path">

          <el-submenu :index="item.id + '' " v-for="item in menulist" :key="item.id">
            <template slot="title">
              <i :class="iconlist[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>

              <el-menu-item :index="'/' + item.path " v-for="item in item.children" :key="item.id" @click="save('/' + item.path)">
                <i class="el-icon-location"></i>
                {{item.authName}}</el-menu-item>

          </el-submenu>

        </el-menu>
      </el-aside>



      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
      iconlist: {
        '125': 'iconfont icon-user',
        '103': 'iconfont icon-3702mima',
        '101': 'iconfont icon-shangpin',
        '102': 'iconfont icon-danju',
        '145': 'iconfont icon-baobiao',
      },
      toggle: false,
      path: ''
    }
  },
  name: "Home",
  created() {
    this.getMenuDate()
    this.path = window.sessionStorage.getItem('activepath')
  },
  methods: {
    async getMenuDate() {
      const {data: res} = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.error(res.meta.message)
      this.menulist = res.data
      console.log(res)
    },
    out() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    toggle_menu() {
      this.toggle = !this.toggle
    },
    save(path) {
      window.sessionStorage.setItem('activepath',path)
      this.path = path
    }
  }
}
</script>

<style scoped>
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 20px;
}
.el-header div {
  display: flex;
  align-items: center;
}
.el-aside {
  background-color: #333744;
}
.el-main {
  background-color: #eaedf1;
  padding-left: 5px;
}
body .el-menu {
  border-right: 0;
}
.bg_box {
  height: 700px;
}
.iconfont {
  margin-right: 10px;
}
.toggle_menu {
  height: 20px;
  font-size: 10px;
  font-weight: 1000;
  color: #eaedf1;
  letter-spacing: 1em;
  text-align: center;
  cursor: pointer;
  margin: 10px 0;
}
.toggle_menu:hover {
  background-color: #0C0C0C;
}
</style>
